package com.itheima.controller.user;


import com.itheima.common.entity.Result;
import com.itheima.common.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/validatecode")
public class ValidatecodeController {

    @Autowired
    RedisTemplate redisTemplate;

    @PostMapping("/send4Order")
    public Result send4Order(@RequestParam String telephone)
    {

        String code = RandomUtil.getFourBitRandom() ;

//        将生成的验证码保存到redis中，
        redisTemplate.opsForValue().set(telephone,code,5*60);

        return new Result(true,"发送成功", code);


    }


    @GetMapping("/send4Login")
    public Result send4Login(@RequestParam String telephone)
    {

        String code = RandomUtil.getFourBitRandom() ;
        redisTemplate.opsForValue().set(telephone,code,5*60);
        return new Result(true,"发送成功", code);

    }




}
